package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.mall.api.entity.MallUserMerchantCollectModel;
import com.mallcloud.mall.mall.service.MallUserMerchantCollectService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户商户收藏表管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/userMerchantCollect")
public class MallUserMerchantCollectController {
    private final MallUserMerchantCollectService mallUserMerchantCollectService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('mall_usermerchantcollect_view')")
    public R<IPage<MallUserMerchantCollectModel>> page(Page page, MallUserMerchantCollectModel dto) {
        return R.ok(mallUserMerchantCollectService.page(page, Wrappers.query(dto)));
    }

    @ApiOperation("列表查询")
    @GetMapping("/list")
    @PreAuthorize("@pms.hasPermission('mall_usermerchantcollect_view')")
    public R<List<MallUserMerchantCollectModel>> list(MallUserMerchantCollectModel dto) {
        return R.ok(mallUserMerchantCollectService.list(Wrappers.query(dto)));
    }

    @ApiOperation("通过id查询")
    @GetMapping("/getInfo")
    @PreAuthorize("@pms.hasPermission('mall_usermerchantcollect_view')")
    public R<MallUserMerchantCollectModel> getInfo(MallUserMerchantCollectModel dto) {
        return R.ok(mallUserMerchantCollectService.getById(dto.getUid()));
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('mall_usermerchantcollect_add')")
    public R<Boolean> save(@RequestBody MallUserMerchantCollectModel dto) {
        return R.ok(mallUserMerchantCollectService.save(dto));
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    @PreAuthorize("@pms.hasPermission('mall_usermerchantcollect_edit')")
    public R<Boolean> updateById(@RequestBody MallUserMerchantCollectModel dto) {
        return R.ok(mallUserMerchantCollectService.updateById(dto));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{uid}")
    @PreAuthorize("@pms.hasPermission('mall_usermerchantcollect_del')")
    public R<Boolean> removeById(@PathVariable Integer uid) {
        return R.ok(mallUserMerchantCollectService.removeById(uid));
    }

    @ApiOperation("批量删除用户商户收藏表")
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('mall_usermerchantcollect_del')")
    public R<Boolean> removeByIds(@RequestBody List<Long> uids) {
        return R.ok(mallUserMerchantCollectService.removeByIds(uids));
    }
}
